import React from 'react';
import { Editor } from '@tiptap/react';

interface ImageButtonProps {
  editor: Editor;
  icon: string;
  title?: string;
}

const ImageButton: React.FC<ImageButtonProps> = ({
  editor,
  icon,
  title = '插入图片'
}) => {
  const handleAddImage = () => {
    const url = window.prompt('请输入图片URL');
    if (url && editor) {
      editor.chain().focus().setImage({ src: url }).run();
    }
  };

  return (
    <button
      onClick={handleAddImage}
      className="toolbar-button"
      title={title}
    >
      <i className="icon">{icon}</i>
    </button>
  );
};

export default ImageButton;